<?php

/**
 * 每天4：40定时更新brandScore 表 品牌指数的分值
 */

ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';

use Biz\model\brand\BrandScore as mBrandScore;
use Biz\cache\brand\BrandScoreCache;

$cacheList = BrandScoreCache::getAllBrandScore();
$dbList = mBrandScore::selectList([], ['brand_id', 'score']);
$dbList = array_column($dbList, null, 'brand_id');
foreach ($cacheList as $brandId => $score) {
    if (isset($dbList[$brandId]) && $score > $dbList[$brandId]['score']) {
        mBrandScore::updateData(['score' => $score], ['brand_id' => $brandId]);
    }
}